package com.ruoyi.common.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author Felix
 */

@AllArgsConstructor
public enum PaymentStatusEnum {

    /**
     * 未支付
     */
    WAITING_PAY(1, "未支付"),
    /**
     * 已支付
     */
    PAID(2, "已支付"),
    /**
     * 支付超时
     */
    TIME_OUT(3, "支付超时"),
    /**
     * 已退款
     */
    REFUND_PAID(4, "已退款"),
    /**
     * 未支付关闭
     */
    APPLY_REFUNDING(5, "申请退款中"),
    /**
     * 审核通过
     */
    REFUND_SUCCESS(6, "审核通过"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static String enumName() {
        return "支付状态";
    }

    public static Optional<PaymentStatusEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static PaymentStatusEnum isExistById(Integer id) {
        return PaymentStatusEnum.findById(id).get();
    }

    public static Map<String, Object> typeMap() {
        return Arrays.stream(values()).collect(Collectors.toMap(e -> e.id + "", e -> e.name));
    }


}
